Learn T-SQL Commands with Samples
Skip Navigation Links
Skip Navigation Links.
Expand DatabaseDatabase
Expand TableTable
Expand ViewView
Expand Stored ProcedureStored Procedure
Expand Data FilteringData Filtering
Expand Data GroupingData Grouping
Expand JoinsJoins
Expand TriggerTrigger
Expand CursorCursor
Expand OperatorsOperators
Expand ConstraintsConstraints
Expand FunctionsFunctions
Expand Conditional ProcessingConditional Processing
Expand LoopingLooping
Expand Error HandlingError Handling
Collapse v.IMP Queriesv.IMP Queries
Expand XMLXML
Expand Query PerformanceQuery Performance
Expand QueriesQueries
Expand NormalizationNormalization
Expand CreateCreate
     

Arrays in SQL

 
EMP
ID Name Country Salary
1 Vijay India 6000
2 Bill USA 8000
3 Kris France 3000
      DECLARE @IDs varchar(10)
      SET     @IDs = '1,7,9'     -- Array of ID No.s

      SELECT ID,Name,Country
      FROM    EMP
      WHERE ( ',' + @IDs ) LIKE ( '%,' + cast( ID as varchar(5)) + ',%' )

    
      
Output
ID Name Country Salary
1 Vijay India 6000